import React, {useContext, useEffect} from 'react';
import {Text, StyleSheet, View, Button} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import {LoginContext} from '../Stacks/HomeStack';

const Cart = () => {
  const loginState = useContext(LoginContext);

  const navigation: any = useNavigation();

  const goToLoginClick = () => {
    navigation.navigate('Login');
  };

  useEffect(() => {
    loginState.login ? {} : goToLoginClick();
  });

  return (
    <View style={styles.containerView}>
      <Text style={styles.textStyle}> 购物车 </Text>
      {loginState.login ? (
        <></>
      ) : (
        <Button title="Login" onPress={goToLoginClick} />
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  containerView: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  textStyle: {
    color: 'tomato',
  },
});

export default Cart;
